import axios from 'axios'
import api from './index'
// 注册：http://localhost:4000/api/user/register
export const register = async (data = {}) => {
    
    return axios.post(
        `${api.url}/api/user/register`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
    
}

// 登录：http://localhost:4000/api/user/login
export const login = async (data = {}) => {
    return axios.post(
        `${api.url}/api/user/login`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    
    .then(response => response.data)
}

// 验证码：http://localhost:4000/api/ver/test
export const test = async (data={})=> {
    return axios.get(
        `${api.url}/api/ver/test`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 轮番图：http://localhost:4000/api/photo/carousel_list
export const carousel_list = async (data={})=> {
    return axios.get(
        `${api.url}/api/photo/carousel_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 上传用户头像: http://localhost:4000/api/user/img
export const imgFn = async (data = {}) => {
    return axios.post(
        `${api.url}/api/user/img`,
        data,
        {
            headers: {
                'Content-Type': 'multipart/form-data',
                 token: localStorage.getItem("TOKEN")
            }
        }
    )
    
    .then(response => response.data)
}

// 修改昵称：http://127.0.0.1:4000/api/user/name
export const nameFn = async (data = {}) => {
    return axios.post(
        `${api.url}/api/user/name`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    
    .then(response => response.data)
}

// 获取用户信息：http://localhost:4000/api/user/list
export const usermess = async (data={})=> {
    return axios.get(
        `${api.url}/api/user/list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 删除账号：http://localhost:4000/api/user/remove
export const remove = async (data = {}) => {
    return axios.post(
        `${api.url}/api/user/remove`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    
    .then(response => response.data)
}

// 上传图片：http://localhost:4000/api/photo/upload
export const uploadImg = async (data = {}) => {
    return axios.post(
        `${api.url}/api/photo/upload`,
        data,
        {
            headers: {
                'Content-Type': 'multipart/form-data',
                 token: localStorage.getItem("TOKEN")
            }
        }
    )
    
    .then(response => response.data)
}

// 查询首页图片：http://localhost:4000/api/user/photo_list
export const photo_list = async (data={})=> {
    return axios.get(
        `${api.url}/api/user/photo_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 获取所有用户信息：http://localhost:4000/api/user/alluser
export const AllList = async (data={})=> {
    return axios.get(
        `${api.url}/api/user/alluser`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
  }

// 获取搜索图片列表：http://localhost:4000/api/search/imgs_list
export const imgs_list = async (data={})=> {
    return axios.get(
        `${api.url}/api/search/imgs_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}